-- guildApplicantVo
-- Author: mm
-- Date: 2018-03-19 15:59:54
-- 公会申请者数据结构

local UserBaseInfo = require("app.public.dao.UserBaseInfo")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

-- message GuildApply {
-- 	base.UserBaseInfo userBaseInfo = 1;
-- 	string inviter = 2; // 邀请人名字
-- 	int32 offlineStamp = 3; // 离线时间戳，为0表示在线
-- }

function ClassRef:ctor(data)
	self._applicantUserBaseInfo = UserBaseInfo.new()
	self._inviter = ""
	self._offlineStamp = -1

	if data then
		self:read(data)
	end
end

function ClassRef:read(data)
	self._applicantUserBaseInfo = UserBaseInfo.new( data.userBaseInfo )
	self._inviter = data.inviter
	self._offlineStamp = data.offlineStamp

	self._applicantUserBaseInfo:setOnline( 0 == self._offlineStamp )
end

-- 是否在线？
function ClassRef:isOnline()
	return 0 == self._offlineStamp
end

-- 离线时间
function ClassRef:offlineStr()
	local offlineStr = ""
	if 0 < self._offlineStamp then -- 离线状态？
		local curTime = math.floor(app.session:getServerTime() or app:getTime())
		--type=2
		--      >1天 return {day},gap
		--      <=1天 return {h,m,s},1
		local params, interval = TimeUtil.secondsToStr( ( curTime - self._offlineStamp ) , 2 )
		if #params == 1 then -- 超过一天？
			local timeList = TimeUtil.secondsToStr(interval, 3)
			offlineStr = string.format( L("offline_state1"), params[1], timeList[1] )
		else
			local hour = params[1]
			if 0 >= hour then
				offlineStr = L("offline_state3")
			else
				offlineStr = string.format( L("offline_state2"), hour )
			end
		end
	end
	return offlineStr
end


function ClassRef:getMemberName()
	return self._applicantUserBaseInfo.name
end
function ClassRef:getMemberId()
	return self._applicantUserBaseInfo.uid
end
function ClassRef:getMemberCombatPower()
	return self._applicantUserBaseInfo.combatPower
end
-- 是否是"我"？
function ClassRef:isMe()
	return self._applicantUserBaseInfo.uid == UD.player.uid
end


-- 返回 userbaseInfo 结构
function ClassRef:getMemberInfo()
	return self._applicantUserBaseInfo
end

-- 返回 推荐人 名字
function ClassRef:getInviterName()
	return self._inviter
end

return ClassRef
